<?php
// This page lets the user logout.

session_start(); // Access the existing session.

// If no cookie is present, redirect the user:
if (!isset($_SESSION['user_id'])) {
	
	// Need the functions to create an absolute URL:
	require_once 'includes/login_functions.inc.php';
	$url = absolute_url();
	header("Location: $url");
	exit(); // Quit the script.
	
} else { // Cancel the session
	
	$_SESSION = array(); // Clear the variables.
	session_destroy(); // Destroy the session itself.
	setcookie('PHPSESSID','',time()-3600,'/','',0,0); // Destroy the cookie.
	// Delete the cookies.
	//setcookie('user_id','',time()-3600,'/','',0,0);
	//setcookie('first_name','',time()-3600,'/','',0,0);
}

// Set the page title and include the HTML header:
$page_title = 'Logged Out!';
include 'includes/header.html';

// Print a customized message:
echo "<h1>Logged Out!</h1>
		<p>You are now logged out!</p>";

include 'includes/footer.html';

?>